<%- contentFor('pageStyle') %>
<!-- BEGIN PAGE LEVEL PLUGINS -->
<link href="/metronic/global/plugins/jquery-multi-select/css/multi-select.css" rel="stylesheet" type="text/css" />
<link href="/metronic/global/plugins/jstree/dist/themes/default/style.min.css" rel="stylesheet" type="text/css" />
<link href="/metronic/global/plugins/bootstrap-daterangepicker/daterangepicker.min.css" rel="stylesheet" type="text/css" />
<style>
  .company-select {
    width: 100%;
  }
</style>
<!-- END PAGE LEVEL PLUGINS -->

<%- contentFor('pageContent') %>
<div class="page-content-wrapper" ng-controller="ActivityCtrl"  >
  <!-- BEGIN CONTENT BODY -->
  <div class="page-content">
    <!-- BEGIN PAGE TITLE-->
    <h3 class="page-title">活动管理
      <small></small>
    </h3>
    <!-- END PAGE TITLE-->
    <!-- END PAGE HEADER-->
    <div class="row">
      <div class="col-md-12">
        <div class="portlet box green">
          <div class="portlet-title">
            <div class="caption">
              活动列表
            </div>
            <div class="actions">
              <button type="button" class="btn purple add-subject-btn" ng-click="openAddModal();"><i class="fa fa-plus"></i> 添加活动</button>
            </div>
          </div>
          <div class="portlet-body">
            <div class="table-scrollable">
              <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                  <th scope="col"> # </th>
                  <th scope="col"> 活动名 </th>
                  <th scope="col"> 描述 </th>
                  <th scope="col"> 参与企业 </th>
                  <th scope="col"> 活动专题 </th>
                  <th scope="col"> 活动试题数量 </th>
                  <th scope="col"> 答题时间（分钟）</th>
                  <th scope="col"> 获奖正确率</th>
                  <th scope="col"> 最大经费（元） </th>
                  <th scope="col"> 红包面额（分） </th>
                  <th scope="col"> 活动时间 </th>
                  <th scope="col"> 状态 </th>
                  <th scope="col" style="width: 152px;"> 操作 </th>
                </tr>
                </thead>  
                <tbody>
                <tr ng-repeat="activity in pageList track by $index" ng-if="pageList.length">
                  <td>{{$index+1}}</td>
                  <td>{{activity.activityCode.substring(0, activity.activityCode.length - 32)}}</td>
                  <td>{{activity.remark}}</td>
                  <td>{{activity.companyIds | getCompanyName:companyMap}}</td>
                  <td>{{activity.subjectIds | getSubjectName:subjectMap}}</td>
                  <td>{{activity.questionNum}}</td>
                  <td>{{activity.answerTime / 60}}</td>
                  <td>{{activity.answerAccuracy}}</td>
                  <td>{{activity.maxMoney}}</td>
                  <td>{{activity.redDenomination}}</td>
                  <td>{{activity.startTime | date:'yyyy年MM月dd日'}}至{{activity.endTime - 3600 * 24 | date:'yyyy年MM月dd日'}}</td>
                  <td>{{activity.active ? '已激活' : '未激活'}}
                  <td>
                    <div>
                      <a href="javascript:;" class="btn dark btn-sm btn-outline sbold uppercase" ng-if="!activity.active" ng-click="$event.stopPropagation(); activeActivity(activity.id);">激活</a>
                      <a href="javascript:;" class="btn dark btn-sm btn-outline sbold uppercase" ng-if="activity.active" ng-click="$event.stopPropagation(); inactiveActivity(activity.id);">取消激活</a>
                      <a href="javascript:;" class="btn dark btn-sm btn-outline sbold uppercase" ng-click="$event.stopPropagation(); openEditModal(activity);">编辑</a>
                      <a href="javascript:;" class="btn dark btn-sm btn-outline sbold uppercase" target="_blank">活动进展</a>
                    </div>
                  </td>
                </tr>
                <tr ng-if="!pageList.length">
                  <td colspan="12">
                    没有数据
                  </td>
                </tr>
                </tfoot>
              </table>
            </div>
            <div class="row">
              <div class="col-md-12">
                <span class="pull-right pagination pagination-info">共{{pageInfo.totalCount}}条</span>
                <uib-pagination total-items="pageInfo.totalCount" ng-model="pageInfo.pageNo" ng-change="listActivity()" items-per-page="pageInfo.pageSize" max-size="5" class="pagination-sm pull-right" boundary-links="true" force-ellipses="true" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;">></uib-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- END CONTENT BODY -->

</div>

<script type="text/ng-template" id="addActivityModal.html">
  <div class="modal-header">
    <h3 class="modal-title">
      <span ng-show="obj.id">编辑</span>
      <span ng-hide="obj.id">新增</span> 活动信息
    </h3>
  </div>
  <div class="modal-body form">
    <form role="form" name="objModalForm" class="form-horizontal form-bordered form-row-stripped">
      <div class="form-body">
        <div class="form-group" ng-class="{'has-error':objModalForm.title.$invalid && objModalForm.title.$dirty}">
          <label class="control-label col-md-3" for="obj_title">活动简名
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input id="obj_title" type="text" name="title" placeholder="" ng-model="obj.activityName" data-required="1" maxlength="50" class="form-control" />
            <span class="help-block has-error" ng-if="objModalForm.title.$dirty">
	          	<span ng-show="objModalForm.title.$error.required">活动简名是必填项.</span>
            </span>
          </div>
        </div>
        <div class="form-group"">
          <label class="control-label col-md-3" for="obj_comps">参与企业
            <span class="required"> * </span>
          </label>
          <div class="col-md-9">
            <select multiple="multiple" class="multi-select" id="company-module-select" name="companys[]">
              <option ng-repeat="item in companyList" value="{{item.id}}" ng-selected="item.selected" ng-repeat-finished ng-hide="item.name == null"></option>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3" for="obj_description">活动专题
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input ng-model="searchText" class="form-control" style="margin-bottom: 10px;" placeholder="专题过滤">
            <div id="course-tree" class="tree-demo" style="max-height: 500px; overflow-y: scroll;">
            </div>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.questionNum.$invalid && objModalForm.questionNum.$dirty}">
          <label class="control-label col-md-3" for="obj_question_num">活动试题数量
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input id="obj_question_num" type="text" name="questionNum" placeholder="" ng-model="obj.questionNum" data-required="1" maxlength="50" class="form-control" 
            ng-pattern="/^[0-9]*$/" />
            <span class="help-block has-error" ng-if="objModalForm.questionNum.$dirty">
	          	<span ng-show="objModalForm.questionNum.$error.required">活动试题数量是必填项.</span>
	          	<span ng-show="objModalForm.questionNum.$error.pattern">请填写正确的活动试题数量.</span>
            </span>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.answerTime.$invalid && objModalForm.answerTime.$dirty}">
          <label class="control-label col-md-3" for="obj_question_num">答题时间（分钟）
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input id="obj_question_num" type="text" name="answerTime" placeholder="" ng-model="obj.answerTime" data-required="1" maxlength="50" class="form-control" 
            ng-pattern="/^[0-9]*$/" />
            <span class="help-block has-error" ng-if="objModalForm.answerTime.$dirty">
	          	<span ng-show="objModalForm.answerTime.$error.required">答题时间是必填项.</span>
	          	<span ng-show="objModalForm.answerTime.$error.pattern">请填写正确的答题时间.</span>
            </span>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.answerAccuracy.$invalid && objModalForm.answerAccuracy.$dirty}">
          <label class="control-label col-md-3">获得奖励的最低正确率
          </label>
          <div class="col-md-4">
            <input type="text" name="answerAccuracy" placeholder="" ng-model="obj.answerAccuracy" class="form-control" 
            ng-pattern="/^[0-9]*$/" />
            <span class="help-block has-error" ng-if="objModalForm.answerAccuracy.$dirty">
	          	<span ng-show="objModalForm.answerAccuracy.$error.pattern">请填写正确的正确率.</span>
            </span>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.maxMoney.$invalid && objModalForm.maxMoney.$dirty}">
          <label class="control-label col-md-3" for="obj_max_money">最大经费（元）
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input id="obj_max_money" type="text" name="maxMoney" placeholder="" ng-model="obj.maxMoney" data-required="1" maxlength="50" class="form-control" 
            ng-pattern="/^[0-9]*.[0-9]*$/" />
            <span class="help-block has-error" ng-if="objModalForm.maxMoney.$dirty">
	          	<span ng-show="objModalForm.maxMoney.$error.required">最大经费是必填项.</span>
	          	<span ng-show="objModalForm.maxMoney.$error.pattern">请填写正确的经费金额.</span>
            </span>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.redDenomination.$invalid && objModalForm.redDenomination.$dirty}">
          <label class="control-label col-md-3" for="obj_denomination">红包面额（分）
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <input id="obj_denomination" type="text" name="redDenomination" placeholder="" readonly ng-model="obj.redDenomination" data-required="1" maxlength="50" class="form-control" 
            ng-pattern="/^[0-9]*$/" ng-minlength="3" />
            <span class="help-block has-error" ng-if="objModalForm.redDenomination.$dirty">
	          	<span ng-show="objModalForm.redDenomination.$error.required">红包面额是必填项.</span>
	          	<span ng-show="objModalForm.redDenomination.$error.pattern">请填写正确的红包面额.</span>
	          	<span ng-show="objModalForm.redDenomination.$error.minlength">红包面额需要大于100分.</span>
            </span>
          </div>
        </div>
        <div class="form-group" ng-class="{'has-error':objModalForm.time.$invalid && objModalForm.time.$dirty}">
          <label class="control-label col-md-3" for="obj_time">活动时间
            <span class="required"> * </span>
          </label>
          <div class="col-md-4">
            <div style="display: inline-block; width: calc(100% - 90px);">
              <div id="reportrange" class="btn default">
                <i class="fa fa-calendar"></i> &nbsp;
                <span> </span>
                <b class="fa fa-angle-down"></b>
              </div>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3">活动描述
          </label>
          <div class="col-md-9">
            <textarea class="forom-control" rows="3" style="width: 100%; max-width: 100%;" ng-model="obj.remark"></textarea>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3" >活动图片</label>
          <div class="col-md-4">
            <img id="activityThumb" ng-src="{{obj.image || '/images/default_image.gif'}}" style="max-height: 150px;">
          </div>
          <div class="col-md-4">
            <div class="btn btn-default" ngf-select="upload($file)">选择文件</div>
            <span class="help-block" >
              <span >建议尺寸750 * 330.</span>
            </span>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3" >宣传图(首页展示)</label>
          <div class="col-md-4">
            <img id="advertisingThumb" ng-src="{{obj.advertisingImage || '/images/default_image.gif'}}" style="max-height: 150px;">
          </div>
          <div class="col-md-4">
            <div class="btn btn-default" ngf-select="upload1($file)">选择文件</div>
            <span class="help-block" >
              <span >建议尺寸750 * 140.</span>
            </span>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3" >活动规则</label>
          <div class="col-md-9">
            <textarea class="forom-control" rows="3" style="width: 100%; max-width: 100%;" ng-model="obj.ruleUrl" placeholder="活动规则URL"></textarea>
          </div>
        </div>
      </div>
    </form>
  </div>
  <div class="modal-footer" loaded>
    <button ng-click="cancel()" class="btn btn-default">取消</button>
    <button ng-click="ok('save')" ng-hide="obj.id" ng-disabled="objModalForm.$invalid" class="btn btn-primary">保存</button>
    <button ng-click="ok('update')" ng-show="obj.id" ng-disabled="objModalForm.$invalid" class="btn btn-primary">保存</button>
  </div>
</script>

<%- contentFor('pagePlugins') %>
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script src="/metronic/global/plugins/jquery-multi-select/js/jquery.multi-select.js" type="text/javascript"></script>
<script src="/metronic/global/plugins/jstree/dist/jstree.min.js" type="text/javascript"></script>
<script src="/metronic/global/plugins/moment.min.js" type="text/javascript"></script>
<script src="/metronic/global/plugins/bootstrap-daterangepicker/daterangepicker.min.js" type="text/javascript"></script>
<!-- END PAGE LEVEL PLUGINS -->

<%- contentFor('pageScripts') %>
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script type="text/javascript">var _NAVID = 'YY';</script>
<script src="/js/admin/activity/activityCtrl.js" type="text/javascript"></script>
<!-- END PAGE LEVEL SCRIPTS -->
